<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../node_modules/vue/dist/vue.global.js"></script>
</head>

<body>
    <div id="app">
        <p>
            <span v-for="item in gooslist" :key="item.id">
                <input type="checkbox" :value="item" v-model="checkedArr" />{{item.title}}
            </span>

        </p>
        <p>
            <input type="text" name="" v-model.number="price1"> -- <input type="text" v-model.number="price2">
            <button @click="getlistFn">搜索</button>
        </p>
        <div>
            <ul>
                <li v-for="item in resultList" :key="item.id">
                    {{item.name}}--{{item.price}}
                </li>
            </ul>
        </div>
    </div>
</body>

</html>
<script>
    const app = Vue.createApp({
        data() {
            return {
                price1: '',
                price2: '',
                gooslist: [
                    {
                        id: 1,
                        title: "男装",
                        children: [
                            {
                                id: 1,
                                name: "劲霸男装",
                                price: 100
                            },
                            {
                                id: 2,
                                name: "海澜之家",
                                price: 150
                            }
                        ]
                    },
                    {
                        id: 2,
                        title: "女装",
                        children: [
                            {
                                id: 1,
                                name: "LV",
                                price: 50
                            },
                            {
                                id: 2,
                                name: "香奈儿",
                                price: 80
                            }
                        ]
                    },
                    {
                        id: 3,
                        title: "水果",
                        children: [
                            {
                                id: 1,
                                name: "榴莲",
                                price: 120
                            },
                            {
                                id: 2,
                                name: "火龙果",
                                price: 20
                            }
                        ]
                    }

                ],
                checkedArr: [], // 选中的类别
                resultList: [] //  搜索后的商品结果
            }
        },
        methods: {
            getlistFn() {
                //  点击搜索
                this.resultList = [];
                this.checkedArr.forEach(item => {
                    item.children.forEach(item1 => {
                        if (item1.price >= this.price1 && item1.price <= this.price2) {
                            this.resultList.push(item1)
                        }
                    })
                })
                console.log(this.resultList);
            }
        },
        created() {
            this.gooslist.forEach(item => {
                item.children.forEach(item1 => {
                    this.resultList.push(item1)

                })
            })
        }
    }).mount('#app')

</script>